package san.java.day15;

/**
 * 线程通信:  以下三个方法只能用在有同步锁的方法或者代码块中
 *  1. wait(): 令当前线程挂起并放弃CPU, 同步资源, 使别的线程可访问并修改共享资源,而当前线程排队等待再次对资源的访问
 *  2. notify(): 唤醒正在排队等待同步资源的线程中优先级最高的结束等待
 *  3. notifyAll(): 唤醒所有线程结束等待
 */

public class Thread_08 {
    public static void main(String[] args) {
        Account account = new Account(100000);
        Account account1 = new Account(100000);

//        for (int i = 0; i < 1000; i++) {
//            Thread thread = new Thread(new User(account, 100));
//            thread.start();
//            try {
//                thread.join();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            System.out.println(account.getMoney());
//        }

        for (int i = 0; i < 1000; i++) {
            new Thread(new User(account, 100), "zfb").start();
            new Thread(new User(account1, 100), "weChat").start();
            System.out.println(account.getTest());
        }

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("test: " + account.getTest());
        System.out.println("money: " + account.getMoney());
    }
}
